package com.littlespider.myhabacus;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.view.View;
import android.widget.RadioButton;

import com.littlespider.myhabacus.activities.BaseActivity;
import com.littlespider.myhabacus.fragments.CompareFragment;
import com.littlespider.myhabacus.fragments.HomeFragment;
import com.littlespider.myhabacus.fragments.MineFragment;
import com.littlespider.myhabacus.fragments.ServiceFragment;

import butterknife.BindView;
import butterknife.OnClick;

public class MainActivity extends BaseActivity {

    @BindView(R.id.rb_one)
    RadioButton rb_one;
    @BindView(R.id.rb_two)
    RadioButton rb_two;
    @BindView(R.id.rb_three)
    RadioButton rb_three;
    @BindView(R.id.rb_four)
    RadioButton rb_four;

    FragmentManager manager;
    Fragment[] fragments = {new HomeFragment(), new CompareFragment(),
            new ServiceFragment(), new MineFragment()};

    @Override
    public int setLayoutRes() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {
        setStatusBarFullTransparent(); //设置状态栏透明
        manager = getFragmentManager();
        FragmentTransaction transaction = manager.beginTransaction();
        transaction.add(R.id.fragment, new HomeFragment());
        transaction.commit();
    }

    @Override
    public void initData() {

    }


    @OnClick({R.id.rb_one, R.id.rb_two, R.id.rb_three, R.id.rb_four})
    public void clickOfBottomViews(View view){
        FragmentTransaction transaction = manager.beginTransaction();
//        for(Fragment currentFragment : fragments){
//            transaction.hide(currentFragment);
//        }
        switch (view.getId()){
            case R.id.rb_one:
                transaction.replace(R.id.fragment, fragments[0]);
//                t.show("one");
//                transaction.show(fragments[0]);
                break;
            case R.id.rb_two:
//                t.show("two");
                transaction.replace(R.id.fragment, fragments[1]);
//                if (!fragments[1].isAdded()){
//                    transaction.add(R.id.fragment, fragments[1]);
//                }
//                transaction.show(fragments[1]);
                break;
            case R.id.rb_three:
                transaction.replace(R.id.fragment, fragments[2]);
//                if (!fragments[2].isAdded()){
//                    transaction.add(R.id.fragment, fragments[2]);
//                }
//                transaction.show(fragments[2]);
                break;
            case R.id.rb_four:
                transaction.replace(R.id.fragment, fragments[3]);
//                if (!fragments[3].isAdded()){
//                    transaction.add(R.id.fragment, fragments[3]);
//                }
//                transaction.show(fragments[3]);
                break;
        }
        transaction.commit();
    }
}
